package com.tianzeculture.stagebao.activity.personal;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

import com.tianzeculture.stagebao.R;
import com.tianzeculture.stagebao.activity.business.PublishNoticeActivity;
import com.tianzeculture.stagebao.base.BaseActivity;
import com.tianzeculture.stagebao.dialog.UnitDialog;
import com.tianzeculture.stagebao.net.ArtistRestUsage;
import com.tianzeculture.stagebao.network.Request;
import com.tianzeculture.stagebao.network.enity.MSG;
import com.tianzeculture.stagebao.network.util.ToastUtil;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/9/8.
 */

public class EditOfferActivity extends BaseActivity {


    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.tvSubtitle)
    TextView tvSubtitle;
    @BindView(R.id.ibtnDelete)
    ImageButton ibtnDelete;
    @BindView(R.id.tvRight)
    TextView tvRight;
    @BindView(R.id.tvWorkPriceUnit)
    TextView tvWorkPriceUnit;
    @BindView(R.id.etStyle)
    EditText etStyle;
    @BindView(R.id.etMoney)
    EditText etMoney;

    String unit = "小时";
    @Request
    ArtistRestUsage artistRestUsage = null;

    private int offerId = 1;

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_edit_offer;
    }

    @Override
    public void initUI() {
        super.initUI();
        tvTitle.setText("才艺报价");
        tvRight.setVisibility(View.VISIBLE);
        tvWorkPriceUnit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                UnitDialog unitDialog = new UnitDialog(EditOfferActivity.this);
                unitDialog.setOnSelectClickListener(new UnitDialog.OnSelectClickListener() {
                    @Override
                    public void onOk(String string) {
                        unit = string;
                        tvWorkPriceUnit.setText(string);
                    }

                    @Override
                    public void onCancel() {

                    }
                });
                unitDialog.show();
            }
        });
        tvRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (TextUtils.isEmpty(etStyle.getText())) {
                    ToastUtil.showShort(EditOfferActivity.this, "职业类型不能为空");
                    return;
                }
                if (TextUtils.isEmpty(etMoney.getText())) {
                    ToastUtil.showShort(EditOfferActivity.this, "职业报价不能为空");
                    return;
                }
                if (TextUtils.isEmpty(tvWorkPriceUnit.getText())) {
                    ToastUtil.showShort(EditOfferActivity.this, "请选择报价单位");
                    return;

                }
                Map<String, String> map = new HashMap<>();
                map.put("unit",unit);
                map.put("name", etStyle.getText().toString().trim());
                map.put("price", etMoney.getText().toString().trim());
                artistRestUsage.offerAdd(offerId, map);
            }
        });
    }

    @Override
    public void refreshUI(int taskId, MSG msg) {
        super.refreshUI(taskId, msg);
        if (taskId == offerId) {
            if (msg.getObj() != null) {
                ToastUtil.showShort(this, "添加成功");
                finish();
            } else {
                ToastUtil.showShort(this, msg.getMessage());
            }
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
